package edu.psu.geovista.app.pcp.toolkits.gui;
/*
 * UnevenRowSectionPane.java
 *
 * Created on April 12, 2004, 10:08 AM
 */

import javax.swing.*;
import java.awt.*;

/**
 *
 * @author  jinchen
 */
public class UnevenRowSectionPane extends javax.swing.JPanel {
    
    /** Creates new form UnevenRowSectionPane */
    public UnevenRowSectionPane() {
        initComponents();
    }

    /**
     *  
     * @param comps     
     * @param weightys  
     */
    public void addToMainPane(JComponent[] comps, double[] weightys) {
         if(comps.length !=weightys.length){
            new IllegalArgumentException(this.getClass().getName() +" : comps'len !=weightys' length");
         }

         clearMainPane();
         for (int i=0;i<comps.length ;i++){
             GridBagConstraints constraints=getContraints(0,i,1.0,weightys[i]);
             mainP.add(comps[i],constraints);
         }

    }


    public void addToControlPane(JComponent cmp) {
        controlP.add(cmp);
    }
    public void clearMainPane(){
        mainP.removeAll();
        mainP.revalidate() ;

    }
    public void clearControlPane(){
        controlP.removeAll();
        controlP.revalidate() ;
    }
    public void removeControlPane(){
        this.remove(controlP);
        this.revalidate() ;
    }

    private GridBagConstraints getContraints(int gridx ,int gridy,double weightx,double weighty){
       GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = gridx;
        gridBagConstraints.gridy = gridy;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = weightx;
        gridBagConstraints.weighty = weighty;
        return gridBagConstraints;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        mainP = new javax.swing.JPanel();
        section1 = new javax.swing.JLabel();
        section2 = new javax.swing.JLabel();
        section3 = new javax.swing.JLabel();
        controlP = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        mainP.setLayout(new java.awt.GridBagLayout());

        section1.setText("section1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 5.0;
        mainP.add(section1, gridBagConstraints);

        section2.setText("section2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 3.0;
        mainP.add(section2, gridBagConstraints);

        section3.setText("section3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 2.0;
        mainP.add(section3, gridBagConstraints);

        add(mainP, java.awt.BorderLayout.CENTER);

        controlP.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jButton1.setText("OK");
        controlP.add(jButton1);

        jButton2.setText("Customize");
        controlP.add(jButton2);

        add(controlP, java.awt.BorderLayout.SOUTH);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel controlP;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JPanel mainP;
    private javax.swing.JLabel section1;
    private javax.swing.JLabel section2;
    private javax.swing.JLabel section3;
    // End of variables declaration//GEN-END:variables
    
}
